
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" contentType="text/html; charset=iso-8859-1" %>
<%@ page import="org.tigr.htc.server.Scheduler" %>

<%!
	// Declare some of static variables here
	private static final String ACCEPT_REQUESTS = "acceptRequests";
	private static final String DENY_REQUESTS = "stopAcceptingRequests";
	private static final String HOLD_SUBMITS = "holdSubmits";
	private static final String START_SUBMITS = "releaseHold";
%>
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <title>HTC Service Admin Console</title>
</head>
<body>
<jsp:include page="../header.jsp" flush="true"></jsp:include>
<%
	// Get an instance of the scheduler to decide how to paint this page
	Scheduler sched = Scheduler.getInstance();
	
	// See if this was triggered by a user submitting a request
	// in which case determine which parameter was requested
	if (request.getParameter("reqType") != null) {
		String requestType = (String) request.getParameter("reqType");
		if (requestType.equals(START_SUBMITS)) {
			sched.setHoldSubmits(false);
		}
		else if (requestType.equals(HOLD_SUBMITS)) {
			sched.setHoldSubmits(true);
		}
		else if (requestType.equals(ACCEPT_REQUESTS)) {
			sched.setAcceptNew(true);
		}
		else if (requestType.equals(DENY_REQUESTS)) {
			sched.setAcceptNew(false);
		}
	}
	
	boolean holdSubmits = sched.isHoldSubmits();
	boolean acceptNew = sched.isAcceptNew();
	String holdImage = null;
	String acceptNewImage = null;
	String holdButtonName = null;
	String acceptButtonName = null;
	
	// Setup some of the variables and values needed by the page
	// Set the icon image to be displayed for holding submits
	if (holdSubmits) {
		holdImage = "start.gif";
		holdButtonName = START_SUBMITS;
	}
	else {
		holdImage = "stop.gif";
		holdButtonName = HOLD_SUBMITS;
	}
	
	// Set the icon image to be displayed for accepting new requests
	if (!acceptNew) {
		acceptNewImage = "start.gif";
		acceptButtonName = ACCEPT_REQUESTS;
	}
	else {
		acceptNewImage = "stop.gif";
		acceptButtonName = DENY_REQUESTS;
	}
	int runningCount = sched.getRunningCount();
	int pendingCount = sched.getPendingCount();
	int runRunnerCount = sched.getActiveRunnerCount();
	int pendingRunnerCount = sched.getPendingRunnerCount();
%>
<h2 align="center"><font face="arial,helvetica,sanserif" >HTCService Administration Console</font></h2>
<form action="admin_console.jsp" method="post">
<table width="100%">
  <tr width="100%">
    <td width="90%">Start/Stop Accepting Requests</td>    
    <td width="10%" align="center"><input type="image" name="reqType" value="<%= acceptButtonName%>" src="<%= acceptNewImage%>"></td>
  </tr>
  <tr width="100%">
    <td width="90%">Hold/Resume Submits</td>
    <td width="10%" align="center"><input type="image" name="reqType" value="<%= holdButtonName%>" src="<%= holdImage%>"></td>
  </tr>
  <tr width="100%">
    <td width="90%">HTC Pending Count</td>
    <td width="10%" align="center"><%= pendingCount%></td>
  </tr>
  <tr width="100%">
    <td width="90%">Pending Runner Count</td>
    <td width="10%" align="center"><%= pendingRunnerCount%></td>
  </tr>
  <tr width="100%">
    <td width="90%">HTC Running Count</td>
    <td width="10%" align="center"><%= runningCount%></td>
  </tr>
  <tr width="100%">
    <td width="90%">Active Runner Count</td>
    <td width="10%" align="center"><%= runRunnerCount%></td>
  </tr>
</table>
</form>
<jsp:include page="admin_footer.jsp" flush="true"></jsp:include>
</body>
</html>